From 2e301fd87651f325a3684fe0cc23acd2ac67bc6a Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=98yvind=20Kol=C3=A5s?= Date: Wed, 21 Mar 2012 18:13:38 +0000 Subject: [PATCH] add babl_format_is_palette --- babl/babl-format.h | 1 + babl/babl-palette.c | 23 +++++++++++++++++------ babl/babl.h | 12 ++++++++++-- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/babl/babl-format.h b/babl/babl-format.h index 01f8f12..bc78f42 100644 --- a/babl/babl-format.h +++ b/babl/babl-format.h @@ -41,6 +41,7 @@ typedef struct int visited; /* for convenience in code while searching for conversion paths */ int format_n; /* whether the format is a format_n type or not */ + int palette; } BablFormat; #endif diff --git a/babl/babl-palette.c b/babl/babl-palette.c index 4655211..8639ba9 100644 --- a/babl/babl-palette.c +++ b/babl/babl-palette.c @@ -21,13 +21,13 @@ #include #include #include +#include "config.h" +#include "babl-internal.h" #include "babl.h" #include "babl-memory.h" #define HASH_TABLE_SIZE 1111 -void babl_sanity (void); - /* A default palette, containing standard ANSI / EGA colors * */ @@ -446,6 +446,14 @@ conv_pala8_pal8 (unsigned char *src, unsigned char *dst, long samples) return samples; } +int +babl_format_is_palette (const Babl *format) +{ + if (format->class_type == BABL_FORMAT) + return format->format.palette; + return 0; +} + /* should return the BablModel, permitting to fetch * other formats out of it? */ @@ -455,8 +463,8 @@ const Babl *babl_new_palette (const char *name, { const Babl *model; const Babl *model_no_alpha; - const Babl *f_pal_u8; - const Babl *f_pal_a_u8; + Babl *f_pal_u8; + Babl *f_pal_a_u8; const Babl *component; const Babl *alpha; BablPalette **palptr; @@ -490,14 +498,17 @@ const Babl *babl_new_palette (const char *name, cname[0] = 'v'; model_no_alpha = babl_model_new ("name", name, component, NULL); cname[0] = 'x'; - f_pal_a_u8 = babl_format_new ("name", name, model, + f_pal_a_u8 = (void*) babl_format_new ("name", name, model, babl_type ("u8"), component, alpha, NULL); cname[0] = 'y'; - f_pal_u8 = babl_format_new ("name", name, model_no_alpha, + f_pal_u8 = (void*) babl_format_new ("name", name, model_no_alpha, babl_type ("u8"), component, NULL); + f_pal_a_u8->format.palette = 1; + f_pal_u8->format.palette = 1; + babl_conversion_new ( model, babl_model ("RGBA"), diff --git a/babl/babl.h b/babl/babl.h index 019b7b9..80333c0 100644 --- a/babl/babl.h +++ b/babl/babl.h @@ -210,6 +210,11 @@ const Babl *babl_new_palette (const char *name, const Babl **format_u8, const Babl **format_u8_with_alpha); +/** + * check whether a format is a palette backed format. + */ +int babl_format_is_palette (const Babl *format); + /** * Assign a palette to a palette format, the data is a single span of pixels * representing the colors of the palette. @@ -220,15 +225,18 @@ void babl_palette_set_palette (const Babl *babl, int count); /** - * reset a palette to initial state. + * reset a palette to initial state, frees up some caches that optimize + * conversions. */ void babl_palette_reset (const Babl *babl); + /** * associate a data pointer with a format/model, this data can be accessed and * used from the conversion functions, encoding color profiles, palettes or - * similar with the data. + * similar with the data, perhaps this should be made internal API, not + * accesible at all from */ void babl_set_user_data (const Babl *babl, void *data); -- 2.30.2